package com.newworld.basketballfire.main.impl;

import com.newworld.basketballfire.main.bean.NoteListParam;
import com.newworld.basketballfire.main.business.NoteBusiness;
import com.newworld.basketballfire.main.utils.CommonUtils;
import com.newworld.basketballfire.service.delegate.NoteServiceDelegate;
import com.newworld.basketballfire.service.exception.ServiceException;
import com.newworld.basketballfire.service.model.ListResult;
import com.newworld.basketballfire.service.model.Note;
import com.newworld.basketballfire.service.model.NoteParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by George on 2019/4/21.
 * NoteServiceDelegateImpl
 */
@Component
public class NoteServiceDelegateImpl implements NoteServiceDelegate {

    @Autowired
    private NoteBusiness noteBusiness;

    @Override
    public Note addNote(NoteParams noteParams) throws ServiceException {
        return noteBusiness.addNote(noteParams);
    }

    @Override
    public Note updateNote(String id, NoteParams noteParams) throws ServiceException {
        noteParams.setId(id);
        return noteBusiness.updateNote(noteParams);
    }

    @Override
    public void deleteNote(String id) throws ServiceException {
        noteBusiness.deleteNote(id);
    }

    @Override
    public Note getNote(String id) throws ServiceException {
        return noteBusiness.getNote(id);
    }

    @Override
    public ListResult<Note> getNoteList(String id, Integer pageNo, Integer pageSize) throws ServiceException {
        NoteListParam noteListParam = new NoteListParam();
        noteListParam.setId(id);
        noteListParam.setPageNo(pageNo);
        noteListParam.setPageSize(pageSize);
        noteListParam.setCurIndex(CommonUtils.getCurIndex(pageNo, pageSize));
        return noteBusiness.getNoteList(noteListParam);
    }
}
